<template>
	<view class="content">
		<view style="height: 2rpx;"></view>
		
		<view class="campusExperience">
			<span>校园实践经历</span>
			<view class="img" @click="toWriteCampusExperience">
				<image src="/subpageA/static/img/my_slices/Group231-2@2x.png" mode="scaleToFill"></image>
			</view>
			<view class="detail" v-for="(item,index) in campusExperienceList" :key="index"
			@click="changeCampusExperience(index)">
				<image src="/subpageA/static/img/my_slices/Frame263@2x.png" mode="scaleToFill"></image>
				<view class="info">
					<span>{{item.startDay}}-{{item.endDay}}</span>
					<span>{{item.name}}{{' '}}{{item.position}}</span>
					<span>{{item.expDesc}}</span>
					
				</view>
				<image id="img" src="/subpageA/static/img/my_slices/Frame222-2@2x.png" mode="scaleToFill"></image>
			</view>
		</view>
		
		<!-- 实习/工作经历部分的样式与上面的校园实践经历的样式完全相同 -->
		<view class="campusExperience">
			<span>实习/工作经历</span>
			<view class="img"  @click="toWriteWorkExperience">
				<image  src="/subpageA/static/img/my_slices/Group231-2@2x.png" mode="scaleToFill"></image>
			</view>
			<view class="detail" v-for="item,index in workExperienceList" :key="index"
			@click="changeWorkExperience(index)">
				<image src="/subpageA/static/img/my_slices/Frame263@2x.png" mode="scaleToFill"></image>
				<view class="info">
					<span>{{item.startDay}}-{{item.endDay}}</span>
					<span>{{item.name}}{{' '}}{{item.position}}</span>
					<span>{{item.expDesc}}</span>
					
				</view>
				<image id="img" src="/subpageA/static/img/my_slices/Frame222-2@2x.png" mode="scaleToFill"></image>
			</view>
		</view>
		
		<view class="open">
			<span>简历开放给商家</span>
			<view class="">
				<uSwitch v-model="public"
				size="12" activeColor="#08C8BD"></uSwitch>
			</view>
		</view>
		
		<button @click="finish">完成</button>
	</view>
</template>

<script>
	import uSwitch from '@/subpageA/uview-ui/components/u-switch/u-switch.vue'
	
	export default {
		data() {
			return {
				campusExperienceList:new Array(0),	//校园经历
				workExperienceList:[],		//实习/工作经历
				public:false,				//是否公开
			};
		},
		components:{
			uSwitch
		},
		onLoad() {
			
			let resumeInfo=uni.getStorageSync('resumeInfo')
			if(resumeInfo.schoolExps){
				this.campusExperienceList=resumeInfo.schoolExps
			}
			if(resumeInfo.workExps){
				this.workExperienceList=resumeInfo.workExps
			}
			
			
			
			
		},
		mounted() {
			this.$bus.$on('getCampusExperience',item=>{
				if(item.current===''){
					console.log('this',this.campusExperienceList);
					this.campusExperienceList.push(item);
				}else{
					this.campusExperienceList.splice(item.current,1,item)
				}
			})
			this.$bus.$on('removeCampusExperience',index=>{
				this.campusExperienceList.splice(index,1)
			})
			
			this.$bus.$on('getWorkExperience',item=>{
				if(item.current===''){
					this.workExperienceList.push(item);
				}else{
					this.workExperienceList.splice(item.current,1,item)
				}
			})
			this.$bus.$on('removeWorkExperience',index=>{
				this.workExperienceList.splice(index,1)
			})
		},
		methods:{
			//添加校园经历
			toWriteCampusExperience(){
				uni.navigateTo({
					url:'./writeCampusExperience'
				})
			},
			//修改校园经历
			changeCampusExperience(index){
				let temp=this.campusExperienceList[index];
				temp.current=index;
				uni.navigateTo({
					url:'./writeCampusExperience?option='+JSON.stringify(temp)
				})
			},
			//添加实习经历
			toWriteWorkExperience(){
				uni.navigateTo({
					url:'./writeWorkExperience'
				})
			},
			//修改实习经历
			changeWorkExperience(index){
				let temp=this.workExperienceList[index];
				temp.current=index;
				uni.navigateTo({
					url:'./writeWorkExperience?option='+JSON.stringify(temp)
				})
			},
			//完成
			finish(){
				//删除‘current’属性
				// for(let v of this.campusExperienceList){
				// 	Reflect.deleteProperty(v,'current')
				// }
				// for(let v of this.workExperienceList){
				// 	Reflect.deleteProperty(v,'current')
				// }
				
				// let tempObj={
				// 	schoolExps:this.campusExperienceList,
				// 	workExps:this.workExperienceList
				// }
				let resumeInfo=uni.getStorageSync('resumeInfo')
				// Object.assign(resumeInfo,tempObj)
				resumeInfo['schoolExps'] = this.campusExperienceList
				resumeInfo['workExps'] = this.workExperienceList
				console.log(resumeInfo);
				
				this.$store.dispatch('initDic').then(()=>{
					this.$http.request({
						url:'/user/resumeSetting',
						data:resumeInfo,
					}).then((result)=>{
						console.log('响应结果',result);
						uni.switchTab({
							url: '/pages/my/my'
						});
					})
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		min-height: 100vh;
		background-color: #F3F7F8;
		
		.campusExperience{
			width: 622rpx;
			padding: 32rpx;
			margin: 32rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			
			>span{
				font-size: 14px;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #001A18;
			}
			
			.img{
				float: right;
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
		
			.detail{
				
				display: flex;
				image:nth-of-type(1){
					width: 18rpx;
					height: 148rpx;
				}
				
				.info{
					
					margin-left: 10rpx;
					
					span{
						display: block;
					}
					span:nth-of-type(1){
						font-size: 14px;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #505E5C;
					}
					span:nth-of-type(2){
						margin-left: 32rpx;
						font-size: 14px;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #001A18;
					}
					span:nth-of-type(3){
						width: 500rpx;
						margin-left: 32rpx;
						font-size: 12px;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #505E5C;
						word-break: break-all;
					}
					
				}
				
				//#ifdef MP-ALIPAY
				#img{
					position: absolute;
					right: 64rpx;
					transform: translate(0,10rpx);
					width: 12rpx;
					height: 42rpx;
				}
				//#endif
				
				image:nth-of-type(2){
					position: absolute;
					right: 64rpx;
					transform: translate(0,10rpx);
					width: 12rpx;
					height: 42rpx;
				}
			}
		
		}
		
		.open{
			width: 622rpx;
			margin: 32rpx;
			padding: 32rpx;
			border-radius: 16rpx;
			background-color: #FFFFFF;
			
			span{
				font-size: 14px;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #001A18;
			}
			
			view{
				float: right;
				margin-top: 4rpx;
			}
		}
		
		button{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 686rpx;
			height: 96rpx;
			margin: 32rpx;
			margin-top: 96rpx;
			background: #08C8BD;
			border-radius: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
</style>
